﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.Mail;
using System.Data;


namespace WebTester
{
    public class OpenScriptException : System.Exception
    {
    }

    public class ScriptData
    {
        public DataTable TestSetTable;
        public DataTable tempTestSetTable;
    }
    
    class OpenScript
    {
        public ScriptData SD = new ScriptData();

        public DataTable TestSetTable
        {
            set { SD.TestSetTable = value; }
            get { return SD.TestSetTable; 
}
        }
        
        public DataTable tempTestSetTable
        {
            set { SD.tempTestSetTable = value; }
            get { return SD.tempTestSetTable; }
        }

        public OpenScript()
        {
            DataColumn column;
            DataColumn[] keys = new DataColumn[1];

            TestSetTable = new DataTable("Test Script");

            column = new DataColumn();
            column.DataType = System.Type.GetType("System.Int32");
            column.ColumnName = "Index";
            column.ReadOnly = false;
            column.Unique = false;
            TestSetTable.Columns.Add(column);
            keys[0] = column;

            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Command";
            column.ReadOnly = false;
            column.Unique = false;
            TestSetTable.Columns.Add(column);

            TestSetTable.PrimaryKey = keys;


        }

        public bool doOpenScript(string absoluteFileName)
        {
            FileInfo testFiles = new FileInfo(absoluteFileName);

            using (StreamReader sr = testFiles.OpenText())
            {

                OpenScript OS = new OpenScript();
                string str = "";
                int idx = 1;
                int lineNo = 0;
                
                try
                {
                  
                    while ((str = sr.ReadLine()) != null)
                    {
                       
                        DataRow row = TestSetTable.NewRow();

                        row["Index"] = idx;
                        row["Command"] = str;
                        TestSetTable.Rows.Add(row);

                        idx++;
                        lineNo++;
                    }

                }
                catch (OpenScriptException)
                {
                   
                   
                    //System.Console.WriteLine("파일의 {0}번째 줄에서 오류가 발생하였습니다.\n{1}개의 아이템에서 발생한 오류입니다.\n오류가 발생한 데이터는 다음과 같습니다.\n\n{2}",lineNo, str);
                }

            }

            return true;
        }

        //public bool tempdoOpenScript()
        //{


        //}



    }

}




